<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<!-- Template inerenti alla scheda -->

<xsl:template match="/dati/scheda" mode="body-scheda" >
	<fo:block-container width="190mm" xsl:use-attribute-sets="layout-style" >
		<fo:block xsl:use-attribute-sets="normal-text">
			<xsl:apply-templates select="body" />
		</fo:block>
	</fo:block-container>	
</xsl:template>

<xsl:template match="/dati/scheda" mode="dim-scheda">
<fo:region-body margin-top="100mm" margin-bottom="10mm"></fo:region-body>
</xsl:template>


<xsl:template match="/dati/scheda" mode="title-scheda" >
	<fo:block-container border-color="black" border-style="hidden" border-width=".5mm" height="15mm" width="190mm" top="68mm" padding=".6mm" position="absolute">	
			<fo:table table-layout="fixed" width="190mm">
				<fo:table-column column-width="100mm"></fo:table-column>
				<fo:table-column column-width="90mm"></fo:table-column>
				<fo:table-body>
					<fo:table-row>
						<fo:table-cell>
							<fo:block xsl:use-attribute-sets="e-title"><xsl:value-of select="metadati/expression/etitle"></xsl:value-of></fo:block>
						</fo:table-cell>
						<fo:table-cell>
						<xsl:choose>
							<xsl:when test="count(metadati/expression//ecreator)=1 and metadati/expression/ecreator[.='']">
								<fo:block></fo:block>
							</xsl:when>
							<xsl:when test="count(metadati/expression//ecreator)>1">
								<fo:block xsl:use-attribute-sets="e-creator"> by 
								<xsl:for-each select="metadati/expression//ecreator"><xsl:value-of select="."></xsl:value-of><xsl:text>, </xsl:text></xsl:for-each></fo:block>
							</xsl:when>
							<xsl:otherwise><fo:block xsl:use-attribute-sets="e-creator"> by <xsl:value-of select="metadati/expression//ecreator"></xsl:value-of></fo:block></xsl:otherwise>
						</xsl:choose>
						</fo:table-cell>
					</fo:table-row>
					<fo:table-row>
						<fo:table-cell>
							<fo:block xsl:use-attribute-sets="w-att"> appartiene a "<xsl:value-of select="metadati/work/wtitle"></xsl:value-of>"
							<xsl:choose>
								<xsl:when test="count(metadati/work//wcreator)=1 and metadati/work/wcreator[.='']">
								<fo:inline></fo:inline>
							</xsl:when>
							<xsl:when test="count(metadati/expression//ecreator)>1">
								<fo:inline> by 
								<xsl:for-each select="metadati/work//wcreator"><xsl:value-of select="."></xsl:value-of><xsl:text>, </xsl:text></xsl:for-each></fo:inline>
							</xsl:when>
							<xsl:otherwise><fo:inline> by <xsl:value-of select="metadati/work/wcreator"></xsl:value-of></fo:inline></xsl:otherwise>
						</xsl:choose>
							
						</fo:block>
						</fo:table-cell>
							<fo:table-cell>
								<fo:block xsl:use-attribute-sets="page">Page <fo:page-number></fo:page-number></fo:block>
							</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
			</fo:block-container>
</xsl:template>

<!-- Fine Template inerenti alla scheda -->

<!-- Template inerenti al response -->

<xsl:template match="/dati/response" mode="back-response">
	<fo:block-container margin-top="70mm" margin-bottom="5mm" height="190mm" border-width="1.5mm" width="190mm" padding="1.5mm" xsl:use-attribute-sets="border" background-image="url(http://ltw0807.web.cs.unibo.it/df/pdf/img/response.png)" >
			<fo:block />
		</fo:block-container>
</xsl:template>


<xsl:template match="/dati/response" mode="body-response">
<fo:block-container xsl:use-attribute-sets="recolor">
<xsl:for-each select=".//metadati">
			<fo:block>
				<xsl:variable name="satana"><xsl:value-of select="expression/eidentifier"></xsl:value-of></xsl:variable>
				<fo:basic-link external-destination="{$satana}"  xsl:use-attribute-sets="link-text">
				<fo:inline xsl:use-attribute-sets="retitle"><xsl:value-of select="expression/etitle"></xsl:value-of></fo:inline></fo:basic-link>
				<xsl:choose>
					<xsl:when test="count(expression//ecreator)=1 and expression/ecreator[.='']">
						<fo:inline></fo:inline>
					</xsl:when>
					<xsl:when test="count(expression//ecreator)>1">
						<fo:inline font-size="10pt" white-space-treatment="preserve" text-indent="10pt">written by
						<xsl:for-each select="expression//ecreator"><xsl:value-of select="."></xsl:value-of><xsl:text>, </xsl:text></xsl:for-each></fo:inline>
					</xsl:when>
					<xsl:otherwise><fo:inline font-size="10pt" white-space-treatment="preserve" text-indent="10pt">written by <xsl:value-of select="expression//ecreator"></xsl:value-of></fo:inline>
					</xsl:otherwise>
				</xsl:choose>
			</fo:block>
			<fo:block>
				<fo:inline xsl:use-attribute-sets="redescription">"<xsl:value-of select="expression/edescription"></xsl:value-of>"</fo:inline>
				<fo:inline xsl:use-attribute-sets="redate"> | <xsl:value-of select="expression/edate"></xsl:value-of></fo:inline>
				
			</fo:block>
			<fo:block>
				<fo:inline font-size="10pt"> from </fo:inline>
				<fo:inline font-size="16pt" font-weight="300"><xsl:value-of select="work/wtitle"></xsl:value-of></fo:inline>
				<xsl:choose>
					<xsl:when test="count(work//wcreator)=1 and work/wcreator[.='']">
						<fo:inline></fo:inline>
					</xsl:when>
					<xsl:when test="count(work//wcreator)>1">
						<fo:inline font-size="10pt"> written by </fo:inline>
						<xsl:for-each select="work//wcreator"><fo:inline font-size="16pt"><xsl:value-of select="."></xsl:value-of><xsl:text>, </xsl:text></fo:inline></xsl:for-each>
					</xsl:when>
					<xsl:otherwise><fo:inline font-size="10pt">written by </fo:inline>
					<fo:inline font-size="16pt"><xsl:value-of select="work/wcreator"></xsl:value-of></fo:inline>
					</xsl:otherwise>
				</xsl:choose>
			</fo:block>
			<!--Separatore fra responses -->
			<fo:list-block>
				<fo:list-item xsl:use-attribute-sets="separator">
					<fo:list-item-label>
						<fo:block></fo:block>
					</fo:list-item-label>
				<fo:list-item-body padding="0mm">
					<fo:block  background-color="inherited-property-value(color)" font-size="26pt">*-*</fo:block>
				</fo:list-item-body>
			  </fo:list-item>
			</fo:list-block>
		</xsl:for-each>		
		</fo:block-container>
</xsl:template>

<!-- Fine Template inerenti al response -->

<!-- Template inerenti all'errore  -->

<xsl:template mode="back-errore" match="/dati/errore">
	<fo:block-container margin-top="70mm" margin-bottom="5mm" height="190mm" border-width="1.5mm" width="190mm" padding="1.5mm" xsl:use-attribute-sets="border" background-image="url(http://ltw0807.web.cs.unibo.it/df/pdf/img/errore.png)" background-repeat="repeat" border-style="hidden" >
			<fo:block />
		</fo:block-container>
</xsl:template>

<xsl:template mode="body-errore" match="/dati/errore">
	<fo:block-container margin-top="20mm" height="160mm" width="190mm" top="10mm"  xsl:use-attribute-sets="errmain">s
				<fo:block xsl:use-attribute-sets="errcode">Errore <xsl:value-of select="codice"></xsl:value-of></fo:block>
			<fo:block xsl:use-attribute-sets="errdesc" margin-top="10mm"><xsl:value-of select="descrizione"></xsl:value-of></fo:block>
			</fo:block-container>
</xsl:template>

<!-- Fine Template inerenti all'errore  -->

<xsl:template name="dim-standard">
<fo:region-body margin-top="80mm" margin-bottom="10mm" /> 
</xsl:template>

<!-- Elementi XHtml-->

		<xsl:template match="//h1"> 
			<fo:block font-size="28pt" line-height="32pt" space-after="22pt"> <xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>	
		<xsl:template match="//h2"> 
			<fo:block font-size="24pt" line-height="28pt" space-after="18pt"><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>	
		<xsl:template match="//h3"> 
			<fo:block font-size="21pt" line-height="24pt" space-after="14pt"><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>	
		<xsl:template match="//h4"> 
			<fo:block font-size="18pt" line-height="21pt" space-after="12pt"><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>	
		<xsl:template match="//h5"> 
			<fo:block font-size="16pt" line-height="19pt" space-after="12pt"><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>	
		<xsl:template match="//h6"> 
			<fo:block font-size="14pt" line-height="17pt" space-after="12pt"><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>	
		<xsl:template match="//p">
			<fo:block font-size="12pt" line-height="15pt"
    space-after="12pt"><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>
		<xsl:template match="//a">
				<fo:basic-link xsl:use-attribute-sets="link-text" external-destination="{@href}">
				<fo:inline><xsl:value-of select="."></xsl:value-of>
				</fo:inline></fo:basic-link>
		</xsl:template>
		<xsl:template match="//div">
		<fo:block><xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>
		
		<xsl:template match="//img">
			<fo:block>
				<fo:external-graphic src="url({@src})"></fo:external-graphic>
			</fo:block>
		</xsl:template>
		<xsl:template match="//image">
			<fo:block>
				<fo:external-graphic src="{@src}" content-height="{@height}" content-width="{@width}"></fo:external-graphic>
			</fo:block>
		</xsl:template>
		<xsl:template match="//b">
			<fo:inline font-weight="bold"><xsl:apply-templates select="*|text()"/></fo:inline>
		</xsl:template>
		<xsl:template match="//i">
		<fo:inline font-style="italic"><xsl:apply-templates select="*|text()"/></fo:inline>
		</xsl:template>
		<xsl:template match="//strong">
		<fo:inline font-weight="bold"><xsl:apply-templates select="*|text()"/></fo:inline>
		</xsl:template>
		<xsl:template match="//big">
		<fo:inline font-size="16pt"><xsl:apply-templates select="*|text()"/></fo:inline>
		</xsl:template>
		<xsl:template match="//hr">
			<fo:block font-size="26pt" text-align="center">
			<fo:external-graphic src="url(http://ltw0807.web.cs.unibo.it/df/pdf/img/bahr.gif)"></fo:external-graphic>
			</fo:block>
		</xsl:template>
		<xsl:template match="//small">
		<fo:inline font-size="12pt"><xsl:apply-templates></xsl:apply-templates></fo:inline>
		</xsl:template>
		<xsl:template match="//sub">
		  <fo:inline vertical-align="sub" font-size="10pt">
			<xsl:apply-templates select="*|text()"/>
		  </fo:inline>
		</xsl:template>
		<xsl:template match="//sup">
			  <fo:inline vertical-align="super" font-size="10pt">
			  <xsl:apply-templates select="*|text()"/></fo:inline>
		</xsl:template>
		<xsl:template match="//tt">
			<fo:inline font-family="monospace"><xsl:apply-templates></xsl:apply-templates></fo:inline>
		</xsl:template>
		<xsl:template match="//address">
			<fo:block font-style="italic"><xsl:apply-templates></xsl:apply-templates></fo:block>
		</xsl:template>
		<xsl:template match="//br">
			<fo:block> </fo:block>
		</xsl:template>
		<xsl:template match="//blockquote">
		  <fo:block start-indent="15mm" end-indent="15mm">
			<xsl:apply-templates select="*|text()"/></fo:block>
		</xsl:template>
		<xsl:template match="//pre">
			<fo:block font-family="monospace" white-space-collapse="false"><xsl:apply-templates select="*|text()" /></fo:block>
		</xsl:template>
		
		<!--List element-->
		<xsl:template match="//dl">
			<fo:block> <xsl:apply-templates select="*|text()" /></fo:block>
		</xsl:template>
		<xsl:template match="//dt">
			<fo:block font-weight="bold"><xsl:apply-templates select="*|text()" /></fo:block>
		</xsl:template>
		<xsl:template match="//dd">
			<fo:block text-indent="10mm"><xsl:apply-templates select="*|text()" /></fo:block>
		</xsl:template>
		
		<xsl:template match="//ol">
				<fo:block provisional-distance-between-starts="5mm" provisional-label-separation="1mm">
				<xsl:attribute name="start-indent">
					<xsl:variable name="precedenti">
					<xsl:choose>
						<xsl:when test="count(ancestor::ul) or count(ancestor::ol)">
							<xsl:value-of select="10+count(ancestor::ul) + count(ancestor::ol)"></xsl:value-of>
						</xsl:when>
						<xsl:otherwise><xsl:text>10</xsl:text></xsl:otherwise>
					</xsl:choose>
					</xsl:variable>
				<xsl:value-of select="concat($precedenti,'mm')"></xsl:value-of>
				</xsl:attribute>
				<xsl:attribute name="space-after">
						<xsl:choose>
							<xsl:when test="ancestor::ul or ancestor::ol"><xsl:text>0pt</xsl:text></xsl:when>
							<xsl:otherwise><xsl:text>12pt</xsl:text></xsl:otherwise>
						</xsl:choose>
				</xsl:attribute>
				<fo:block-container>
				<xsl:apply-templates select="*" /></fo:block-container>
				</fo:block>
		</xsl:template>
		
		<xsl:template match="//ol/li">
			<fo:block>
				<fo:inline>
				<xsl:choose>
						<xsl:when test="count(descendant::ul)>=1 or count(descendant::ol)>=1"><fo:inline></fo:inline></xsl:when>
						<xsl:otherwise><fo:inline><xsl:number count="*/li"></xsl:number></fo:inline></xsl:otherwise>
					</xsl:choose>
				</fo:inline>
				<xsl:choose>
					<xsl:when test="count(descendant::ul)>=1 or count(descendant::ol)>=1"><fo:inline></fo:inline></xsl:when>
					<xsl:otherwise><fo:inline>) </fo:inline></xsl:otherwise>
				</xsl:choose>
						<xsl:apply-templates select="*|text()"></xsl:apply-templates>
			</fo:block>
		</xsl:template>
		
		<xsl:template match="//ul">
			<fo:block provisional-distance-between-starts="5mm" provisional-label-separation="1mm">
				<xsl:attribute name="start-indent">
				<xsl:variable name="precedenti">
					<xsl:choose>
						<xsl:when test="count(ancestor::ul) or count(ancestor::ol)">
							<xsl:value-of select="10+count(ancestor::ul) + count(ancestor::ol)"></xsl:value-of>
						</xsl:when>
						<xsl:otherwise><xsl:text>10</xsl:text></xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:value-of select="concat($precedenti,'mm')"></xsl:value-of>
				</xsl:attribute>
				<xsl:attribute name="space-after">
						<xsl:choose>
							<xsl:when test="ancestor::ul or ancestor::ol"><xsl:text>0pt</xsl:text></xsl:when>
							<xsl:otherwise><xsl:text>12pt</xsl:text></xsl:otherwise>
						</xsl:choose>
				</xsl:attribute>
				<fo:block-container>
				
				<xsl:apply-templates select="*" /></fo:block-container>
			</fo:block>
		</xsl:template>
		<xsl:template match="//ul/li">
			<fo:block>
				<fo:inline>
				<xsl:choose>
						<xsl:when test="count(descendant::ul)>=1 or count(descendant::ol)>=1"><fo:inline></fo:inline></xsl:when>
						<xsl:otherwise><fo:inline>• </fo:inline></xsl:otherwise>
					</xsl:choose>
				</fo:inline>
				<xsl:apply-templates select="*|text()"></xsl:apply-templates>
			</fo:block>
		</xsl:template>
		
		<!-- Element Inline -->
		<xsl:template match="//abbr">
			<fo:inline><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//acronym">
			<fo:inline><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//cite">
			<fo:inline font-style="italic"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//dfn">
			<fo:inline font-style="italic"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//code">
			<fo:inline font-family="monospace" font-size="9pt"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//em">
			<fo:inline font-style="italic"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//kdb">
			<fo:inline font-family="monospace" font-size="9pt"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//q">
			<fo:inline font-style="italic"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//samp">
			<fo:inline font-family="monospace" font-size="9pt"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="//span">
			<xsl:apply-templates select="*|text()" />
		</xsl:template>
		<xsl:template match="//var">
			<fo:inline font-style="italic" font-family="monospace"><xsl:apply-templates select="*|text()" /></fo:inline>
		</xsl:template>
		<xsl:template match="form"></xsl:template>
		<xsl:template match="table"></xsl:template>
		<xsl:template match="option"></xsl:template>
	<!-- Fine Elementi XHtml-->	
	
</xsl:stylesheet>
